﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="mtaarinimed_arinimi", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MtaarinimedArinimi))]
    public class MtaarinimedArinimiSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMtaarinimedArinimi clazz;
        
        public MtaarinimedArinimiSerializer(IMtaarinimedArinimi clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("rea_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.ReaId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ark");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Ark))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("arinimi");
            if (clazz.Arinimi!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Arinimi))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Arinimi");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("eltyyp");
            if (clazz.Eltyyp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eltyyp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eltyyp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("algus_kpv");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.AlgusKpv))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("lopp_kpv");
            if (clazz.LoppKpv!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.LoppKpv))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="rea_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaarinimed_arinimi>rea_id");
                }
                clazz.ReaId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("rea_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaarinimed_arinimi>rea_id", Reader.LocalName);
            }
            if (Reader.LocalName=="ark") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaarinimed_arinimi>ark");
                }
                clazz.Ark = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ark")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaarinimed_arinimi>ark", Reader.LocalName);
            }
            if (Reader.LocalName=="arinimi") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaarinimed_arinimi>arinimi");
                }
                clazz.Arinimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("arinimi")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaarinimed_arinimi>arinimi", Reader.LocalName);
            }
            if (Reader.LocalName=="eltyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaarinimed_arinimi>eltyyp");
                }
                clazz.Eltyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("eltyyp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaarinimed_arinimi>eltyyp", Reader.LocalName);
            }
            if (Reader.LocalName=="algus_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>mtaarinimed_arinimi>algus_kpv");
                }
                clazz.AlgusKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("algus_kpv")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaarinimed_arinimi>algus_kpv", Reader.LocalName);
            }
            if (Reader.LocalName=="lopp_kpv") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LoppKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("lopp_kpv")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>mtaarinimed_arinimi>lopp_kpv", Reader.LocalName);
            }
        }
    }
}
